<template>
	<view>
		<div class="body">

		</div>

		<!-- <u-navbar title="套餐" :placeholder="true" leftIconColor="#fff" :autoBack="true" :bgColor="bgColor"
			:titleStyle="titleStyle"></u-navbar> -->
		<headerinfo></headerinfo>
		<!-- <headertop :inv="5"></headertop> -->
		<backos></backos>
		<view class="width60">
			<view class="userBox">
				<image :src="userData.avatar" mode="aspectFill"></image>
				<view class="label">
					{{ userData.realname?userData.realname:userData.nickname?userData.nickname:userData.username  }}
				</view>
				<view class="desc" v-if="userData.checkinRsp && userData.checkinRsp.privilegePeriodValidUntil">
					套餐到期时间：{{userData.checkinRsp.privilegePeriodValidUntil}}
				</view>

				纪念币余额：<span
					style="color: red;">{{(userData.checkinRsp&&userData.checkinRsp.remainFamilyCoin)?(userData.checkinRsp.remainFamilyCoin):''}}</span>


			</view>
			<view class="cardList">
				<view class="list" @click="changeInv(index)" :class="Inv == index?'active':''"
					v-for="(item,index) in paySet" :key="index">
					<view class="label">
						{{item.name}}: {{item.familyCoin}}家庭币
					</view>
					<view class="price">
						<span>￥</span>{{item.pay}}
					</view>
				</view>
			</view>
			<!-- <view class="qianyi">
				<view class="label">
					套餐权益：<span style="color: #de4849;font-weight: bold;">{{tablist[Inv].familyCoin}}家庭币
						{{tablist[Inv].ossSpace}}M空间</span>
				</view>
			
			</view> -->

			<view class="" style="display: flex;align-items: center;justify-content: space-between;padding: 0 10%;">
				<view class="buy" @click="buy(1)">
					微信支付
				</view>

			<!-- 	<view class="buy" @click="buy(2)">
					支付宝支付
				</view> -->
			</view>



			<view class="mt-3 font p-2">
				注：现有需要家庭币项目如下：
			</view>

			<view class="flex align-center justify-between border-bottom font font-weight-bold mt-2 ml-5 mr-5 mb-2">
				<text>项目</text>
				<text>消耗家庭币数量</text>
			</view>

			<view class="flex align-center justify-between border-bottom mb-2" v-for="(item,index) in payItems"
				:key="index">
				<text class="ml-5 font">{{item.name}}</text>
				<text class="mr-5 font">{{item.familyCoin}}</text>
			</view>
		</view>
		<el-dialog title="扫码支付" :visible.sync="payDia" width="300px">
			<!-- <tki-qrcode cid="qrcode1" ref="qrcode" :val="val" :size="size" :onval="onval" :loadMake="loadMake"
				:usingComponents="true" /> -->

			<tki-qrcode cid="qrcode1" ref="qrcode" :val="val" :size="size" :onval="onval" :loadMake="true"
				:usingComponents="true" />
			<span slot="footer" class="dialog-footer" style="text-align: center;">
				<el-button type="primary" @click="getAllData()">我已支付</el-button>
			</span>


		</el-dialog>



	</view>
</template>

<script>
	const util = require('@/common/refresh.js');
	import tkiQrcode from "@/components/tki-qrcode/tki-qrcode.vue"
	export default {
		components: {
			tkiQrcode
		},
		data() {
			return {
				formUrl: '',
				global: this.$global,
				val: '', // 要生成的二维码值
				size: 500, // 二维码大小
				icon: '', // 二维码图标
				iconsize: 40, // 二维码图标大小
				lv: 3, // 二维码容错级别 ， 一般不用设置，默认就行
				onval: true, // val值变化时自动重新生成二维码
				loadMake: false, // 组件加载完成后自动生成二维码
				src: '', // 二维码生成后的图片地址或base64
				payDia: false,
				payImg: '',
				payItems: [],
				bgColor: '#de4849',
				titleStyle: {
					color: '#fff'
				},
				Inv: 0,
				paySet: [],
				tablist: [],
				userData: {},
				code: ''
			};
		},
		onLoad() {
			this.getUserData();
			this.getData();
			this.getData2();
		},
		mounted() {},
		methods: {
			getAllData() {
				this.getUserData();
				this.getData();
				this.getData2();
				this.payDia = false
			},
			buy: util.throttle(function(type) {
				let totalFee = this.paySet[this.Inv].pay
				let description = '充值-心之归宿会员'
				let app = this
				var payType = 'WECHAT_PAY'

				if (type == 2) {
					payType = 'ALI_PAY'
				}

				let data = {
					code: '',
					description: description,
					totalFee: totalFee,
					payType: payType,
					width: 200
				}

				app.$api.wxMiniPayGet(data).then(params => {
					console.log('wxMiniPayGet result',params.data.qrcodeUrl);
					if (type == 1) {
						this.payDia = true
						this.val = params.data.qrcodeUrl
						// this.val = 'weixin://wxpay/bizpayurl?pr=dgtW7enz1'
						this.$forceUpdate()
					} else {
						this.formUrl = params.data
						//将接口返回的Form表单显示到页面
						document.querySelector('body').innerHTML = this.formUrl; // body对应上面的class	 
						this.$nextTick(() => {
							console.log(document.forms,
							"form"); //跳转之前,可以先打印看看forms,确保后台数据和forms正确,否则，可能会出现一些奇奇怪怪的问题 ╮(╯▽╰)╭
							document.forms['0'].submit(); //重点--这个才是跳转页面的核心,获取第一个表单并提交
						});
					}
				})
			}),
			getUserData() {
				this.$api.myInfo().then(res => {
					this.userData = res
					console.log('用户信息')
				})
			},
			getData() {
				// let arr = []
				// this.$api.getPaySet().then(res => {
				// 	console.log(res)
				// 	arr = [res.set.month, res.set.season, res.set.year]
				// 	this.tablist = arr
				// })
			},
			getData2() {
				let arr = []
				this.$api.fetPaySet().then(res => {
					console.log('fetPaySet', res)
					this.paySet = res.paySet
					this.payItems = res.payItems
					// arr = [res.set.month, res.set.season, res.set.year]
					// this.tablist = arr
				})
			},
			changeInv(index) {
				if (this.Inv == index) {
					return
				}

				this.Inv = index
			}
		}
	};
</script>

<style lang="scss" scoped>
	.form {
		width: 600px;
		margin: 0 auto;
		box-shadow: 0 0 3px #ccc;
		border-radius: 10px;
		padding: 20px 30px;
	}

	.qianyi {
		padding: 20rpx;
		margin-top: 30rpx;

	}

	.userBox {
		position: relative;
		padding: 20rpx;
		padding-left: 140rpx;
		margin-top: 30rpx;

		.label {
			margin-bottom: 10rpx;
		}

		.desc {
			font-size: 26rpx;
			color: #ababab;
		}

		image {
			position: absolute;
			left: 20rpx;
			top: 50%;
			transform: translateY(-50%);
			width: 100rpx;
			height: 100rpx;
			border-radius: 50px;
		}
	}

	.buy {
		width: 30%;
		height: 90rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border: 1px solid #e8e8e8;
		border-radius: 5px;
		border-color: #de4849;
		background-color: #de4849;
		color: #fff;
		margin: 0 auto;
		margin-top: 30rpx;
		cursor: pointer;
	}

	.cardList {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex-direction: column;
		padding: 20rpx;

		.list {
			width: 100%;
			background-color: #f7f9fc;
			padding: 20rpx;
			box-sizing: border-box;
			border-radius: 10rpx;
			border: 1px solid #f7f9fc;
			cursor: pointer;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 20rpx;

			.label {
				font-weight: bold;
			}

			.price {
				font-size: 40rpx;
				font-weight: bold;
				color: #de4849;

				span {
					font-size: 28rpx;
					cursor: pointer;
				}
			}

		}

		.active {
			border-color: #de4849;
		}
	}
</style>